﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using LF3.Moduls;
using CP.DBService;
using Oracle.ManagedDataAccess.Client;
using System.Data;

namespace LF3.Repositories
{
    public class LF_ScheduleRepository
    {
        DBHelper db = DBHelper.CreateInstance();
        public IList<Lf_Schedule> GetNotStartSchedulers()
        {
            return db.ExecuteObject<Lf_Schedule>(@"select * from lf_schedule 
                                                where heat_status = '0' or heat_status = '1' ");
        }

        public Lf_Schedule GetSchedulerByID(int scheduleID)
        {
            return db.ExecuteSingleObject<Lf_Schedule>(string.Format(@"select * from lf_schedule 
                                                where bofscheduleid = {0}", scheduleID));
        }

        public void HeatAnnounce(long scheduleID)
        {
            string errmsg = string.Empty;

            try
            {
                OracleParameter[] parameters ={
                new OracleParameter("p_scheduleid",OracleDbType.Int64), 
                new OracleParameter("p_errmsg",OracleDbType.Varchar2,200)
　　　　　　　　　　　　　};
                parameters[0].Direction = ParameterDirection.Input; 
                parameters[1].Direction = ParameterDirection.Output;

                parameters[0].Value = scheduleID;  
                db.ExecuteNonQuery("proc_heat_announce", parameters, CommandType.StoredProcedure);
                errmsg = parameters[1].Value.ToString();
                if (errmsg != "null")
                    throw new Exception(errmsg);
            }
            catch (Exception e)
            {
                throw e;
            }
        }

        public void HeatCancelAnnounce(int scheduleID)
        {
            string errmsg = string.Empty;

            try
            {
                OracleParameter[] parameters ={
                new OracleParameter("p_scheduleid",OracleDbType.Int32), 
                new OracleParameter("p_errmsg",OracleDbType.Varchar2,200)
　　　　　　　　　　　　　};
                parameters[0].Direction = ParameterDirection.Input;
                parameters[1].Direction = ParameterDirection.Output;

                parameters[0].Value = scheduleID;
                db.ExecuteNonQuery("proc_heat_cancel_announce", parameters, CommandType.StoredProcedure);
                errmsg = parameters[1].Value.ToString();
                if (errmsg != "null")
                    throw new Exception(errmsg);
            }
            catch (Exception e)
            {
                throw e;
            }
        }

        public void HeatEnd(int scheduleID)
        {
            string errmsg = string.Empty;

            try
            {
                OracleParameter[] parameters ={
                new OracleParameter("p_scheduleid",OracleDbType.Int32), 
                new OracleParameter("p_errmsg",OracleDbType.Varchar2,200)
　　　　　　　　　　　　　};
                parameters[0].Direction = ParameterDirection.Input;
                parameters[1].Direction = ParameterDirection.Output;

                parameters[0].Value = scheduleID;
                db.ExecuteNonQuery("proc_heat_end", parameters, CommandType.StoredProcedure);
                errmsg = parameters[1].Value.ToString();
                if (errmsg != "null")
                    throw new Exception(errmsg);
            }
            catch (Exception e)
            {
                throw e;
            }
        }
    }
}
